

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>7.8. Constants and unit conversion — MDAnalysis.core.units &mdash; MDAnalysis v0.7.5-devel documentation</title>
    <link rel="stylesheet" href="../../_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.7.5-devel',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within MDAnalysis v0.7.5-devel documentation"
          href="../../_static/opensearch.xml"/>
    <link rel="shortcut icon" href="../../_static/mdanalysis-logo.ico"/>
    <link rel="top" title="MDAnalysis v0.7.5-devel documentation" href="../../index.html" />
    <link rel="up" title="7. Core modules" href="../core_modules.html" />
    <link rel="next" title="7.9. Helper functions — MDAnalysis.core.util" href="util.html" />
    <link rel="prev" title="7.7. Fast QCP RMSD structure alignment — MDAnalysis.core.qcprot" href="qcprot.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="util.html" title="7.9. Helper functions — MDAnalysis.core.util"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="qcprot.html" title="7.7. Fast QCP RMSD structure alignment — MDAnalysis.core.qcprot"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">MDAnalysis v0.7.5-devel documentation</a> &raquo;</li>
          <li><a href="../core_modules.html" accesskey="U">7. Core modules</a> &raquo;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/mdanalysis-logo-200x150.png" alt="Logo"/>
            </a></p>
  <h3><a href="../../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">7.8. Constants and unit conversion &#8212; <tt class="docutils literal"><span class="pre">MDAnalysis.core.units</span></tt></a><ul>
<li><a class="reference internal" href="#conversions">7.8.1. Conversions</a></li>
<li><a class="reference internal" href="#functions">7.8.2. Functions</a></li>
<li><a class="reference internal" href="#data">7.8.3. Data</a></li>
<li><a class="reference internal" href="#references">7.8.4. References</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="qcprot.html"
                        title="previous chapter">7.7. Fast QCP RMSD structure alignment &#8212; <tt class="docutils literal docutils literal docutils literal"><span class="pre">MDAnalysis.core.qcprot</span></tt></a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="util.html"
                        title="next chapter">7.9. Helper functions &#8212; <tt class="docutils literal docutils literal"><span class="pre">MDAnalysis.core.util</span></tt></a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../_sources/documentation_pages/core/units.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <span class="target" id="module-MDAnalysis.core.units"></span><div class="section" id="constants-and-unit-conversion-mdanalysis-core-units">
<h1>7.8. Constants and unit conversion &#8212; <a class="reference internal" href="#module-MDAnalysis.core.units" title="MDAnalysis.core.units"><tt class="xref py py-mod docutils literal"><span class="pre">MDAnalysis.core.units</span></tt></a><a class="headerlink" href="#constants-and-unit-conversion-mdanalysis-core-units" title="Permalink to this headline">¶</a></h1>
<p>The base units of MDAnalysis are <em>Angstrom</em> for <em>length</em> (1 Angstrom =
0.1 nm = 10^-10 m) and <em>ps</em> (pico second) for <em>time</em> (1 ps = 10^-12
sec).</p>
<p>All conversions: the conversion factor f to a unit b&#8217; for a quantity X
(whose numeric value relative to the base unit b is stored in the
program) is a quantity with unit <cite>b&#8217;/b</cite>. In the dictionaries below only
the numeric value <cite>f(b-&gt;b&#8217;)</cite> is stored:</p>
<div class="highlight-python"><pre>X/b' = f(b-&gt;b') * X/b</pre>
</div>
<p><a class="reference internal" href="#MDAnalysis.core.units.get_conversion_factor" title="MDAnalysis.core.units.get_conversion_factor"><tt class="xref py py-func docutils literal"><span class="pre">get_conversion_factor()</span></tt></a> returns the appropriate factor f(b-&gt;b&#8217;).</p>
<p>Conversion is done via the base units:</p>
<div class="highlight-python"><pre>x is in u1: from u1 to b:  x'  = x  / factor[u1]
            from b  to u2: x'' = x' * factor[u2]
so f[u1,u2] = factor[u2]/factor[u1]</pre>
</div>
<div class="section" id="conversions">
<h2>7.8.1. Conversions<a class="headerlink" href="#conversions" title="Permalink to this headline">¶</a></h2>
<p>density conversion factor. Base unit is A**-3:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">n</span><span class="o">/</span><span class="n">x</span> <span class="o">=</span> <span class="n">n</span><span class="o">/</span><span class="n">A</span><span class="o">**</span><span class="mi">3</span> <span class="o">*</span> <span class="n">densityUnit_factor</span><span class="p">[</span><span class="n">x</span><span class="p">]</span>
</pre></div>
</div>
<p>nm:</p>
<div class="highlight-python"><pre>f = 1 A^-3/1 nm^-3 = 1/(10A)^-3 = 1/1000</pre>
</div>
<p>Molar:</p>
<div class="highlight-python"><pre>factor = 1 A**-3 / (N_Avogadro * (10**-9 dm)**-3)</pre>
</div>
<p>relative to a density rho0 in g/cm^3:</p>
<div class="highlight-python"><pre>M(H2O) = 18 g/mol   Molar mass of water

factor = 1/(1e-24 * N_Avogadro / M(H2O))</pre>
</div>
<p>from <cite>rho/rho0 = n/(N_A * M**-1) / rho0</cite>  where <cite>[n] = 1/Volume</cite>, <cite>[rho] = mass/Volume</cite></p>
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">Maybe we should simply use <a class="reference external" href="http://packages.python.org/quantities/">Quantities</a> instead of this
home grown attempt?</p>
</div>
</div>
<div class="section" id="functions">
<h2>7.8.2. Functions<a class="headerlink" href="#functions" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="MDAnalysis.core.units.get_conversion_factor">
<tt class="descclassname">MDAnalysis.core.units.</tt><tt class="descname">get_conversion_factor</tt><big>(</big><em>unit_type</em>, <em>u1</em>, <em>u2</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.units.get_conversion_factor" title="Permalink to this definition">¶</a></dt>
<dd><p>generate the conversion factor u1 -&gt; u2 by using the base unit as an intermediate</p>
<p>f[u1 -&gt; u2] = factor[u2]/factor[u1]</p>
<p>Conversion of X (in u1) to X&#8217; (in u2):</p>
<blockquote>
<div>X&#8217; = conversion_factor * X</div></blockquote>
</dd></dl>

<dl class="function">
<dt id="MDAnalysis.core.units.convert">
<tt class="descclassname">MDAnalysis.core.units.</tt><tt class="descname">convert</tt><big>(</big><em>x</em>, <em>u1</em>, <em>u2</em><big>)</big><a class="headerlink" href="#MDAnalysis.core.units.convert" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert value in unit <em>u1</em> to <em>u2</em>.</p>
</dd></dl>

</div>
<div class="section" id="data">
<h2>7.8.3. Data<a class="headerlink" href="#data" title="Permalink to this headline">¶</a></h2>
<dl class="data">
<dt id="MDAnalysis.core.units.lengthUnit_factor">
<tt class="descclassname">MDAnalysis.core.units.</tt><tt class="descname">lengthUnit_factor</tt><a class="headerlink" href="#MDAnalysis.core.units.lengthUnit_factor" title="Permalink to this definition">¶</a></dt>
<dd><p>The basic unit of <em>length</em> in MDAnalysis is the Angstrom.
Conversion factors between the base unit and other lengthUnits <em>x</em> are stored.
Conversions follow <cite>L/x = L/Angstrom * lengthUnit_factor[x]</cite>.
<em>x</em> can be <em>nm</em>/<em>nanometer</em> or <em>fm</em>.</p>
</dd></dl>

<dl class="data">
<dt id="MDAnalysis.core.units.N_Avogadro">
<tt class="descclassname">MDAnalysis.core.units.</tt><tt class="descname">N_Avogadro</tt><a class="headerlink" href="#MDAnalysis.core.units.N_Avogadro" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference external" href="http://physics.nist.gov/cgi-bin/cuu/Value?na">Avogadro&#8217;s constant</a> in mol**-1,</p>
</dd></dl>

<dl class="data">
<dt id="MDAnalysis.core.units.water">
<tt class="descclassname">MDAnalysis.core.units.</tt><tt class="descname">water</tt><a class="headerlink" href="#MDAnalysis.core.units.water" title="Permalink to this definition">¶</a></dt>
<dd><dl class="docutils">
<dt>water density values ay 1179: T=298K, P=1atm <a class="reference internal" href="#jorgensen1998">[Jorgensen1998]</a></dt>
<dd><table border="1" class="first last docutils">
<colgroup>
<col width="47%" />
<col width="53%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">model</th>
<th class="head">g cm**-3</th>
</tr>
</thead>
<tbody valign="top">
<tr><td>SPC</td>
<td>0.985(1)</td>
</tr>
<tr><td>TIP3P</td>
<td>1.002(1)</td>
</tr>
<tr><td>TIP4P</td>
<td>1.001(1)</td>
</tr>
<tr><td>exp</td>
<td>0.997</td>
</tr>
</tbody>
</table>
</dd>
</dl>
<p>and molar mass 18.016 g mol**-1.</p>
</dd></dl>

<dl class="data">
<dt id="MDAnalysis.core.units.densityUnit_factor">
<tt class="descclassname">MDAnalysis.core.units.</tt><tt class="descname">densityUnit_factor</tt><a class="headerlink" href="#MDAnalysis.core.units.densityUnit_factor" title="Permalink to this definition">¶</a></dt>
<dd><p>The basic unit for <em>densities</em> is Angstroem**(-3), i.e.
the volume per molecule in A**3. Especially for water
it can be convenient to measure the density relative to bulk, and
hence a number of values are pre-stored in <a class="reference internal" href="#MDAnalysis.core.units.water" title="MDAnalysis.core.units.water"><tt class="xref py py-data docutils literal"><span class="pre">water</span></tt></a>.</p>
</dd></dl>

<dl class="data">
<dt id="MDAnalysis.core.units.timeUnit_factor">
<tt class="descclassname">MDAnalysis.core.units.</tt><tt class="descname">timeUnit_factor</tt><a class="headerlink" href="#MDAnalysis.core.units.timeUnit_factor" title="Permalink to this definition">¶</a></dt>
<dd><p>For <em>time</em>, the basic unit is ps; in particular CHARMM&#8217;s
1 <a class="reference external" href="http://www.charmm.org/html/documentation/c35b1/usage.html#%20AKMA">AKMA</a> time unit = 4.888821E-14 sec is supported.</p>
</dd></dl>

<dl class="data">
<dt id="MDAnalysis.core.units.chargeUnit_factor">
<tt class="descclassname">MDAnalysis.core.units.</tt><tt class="descname">chargeUnit_factor</tt><a class="headerlink" href="#MDAnalysis.core.units.chargeUnit_factor" title="Permalink to this definition">¶</a></dt>
<dd><p><em>Charge</em> is measured in multiples of the <a class="reference external" href="http://physics.nist.gov/cgi-bin/cuu/Value?e">electron charge</a>
<em>e</em> =  1.602176487 x 10**(-19) C.</p>
</dd></dl>

<dl class="data">
<dt id="MDAnalysis.core.units.conversion_factor">
<tt class="descclassname">MDAnalysis.core.units.</tt><tt class="descname">conversion_factor</tt><a class="headerlink" href="#MDAnalysis.core.units.conversion_factor" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#MDAnalysis.core.units.conversion_factor" title="MDAnalysis.core.units.conversion_factor"><tt class="xref py py-data docutils literal"><span class="pre">conversion_factor</span></tt></a> is used by <a class="reference internal" href="#MDAnalysis.core.units.get_conversion_factor" title="MDAnalysis.core.units.get_conversion_factor"><tt class="xref py py-func docutils literal"><span class="pre">get_conversion_factor()</span></tt></a>:
Note: any observable with a unit (i.e. one with an entry in
the <tt class="xref py py-attr docutils literal"><span class="pre">unit</span></tt> attribute) needs an entry in <a class="reference internal" href="#MDAnalysis.core.units.conversion_factor" title="MDAnalysis.core.units.conversion_factor"><tt class="xref py py-data docutils literal"><span class="pre">conversion_factor</span></tt></a></p>
</dd></dl>

<dl class="data">
<dt id="MDAnalysis.core.units.unit_types">
<tt class="descclassname">MDAnalysis.core.units.</tt><tt class="descname">unit_types</tt><a class="headerlink" href="#MDAnalysis.core.units.unit_types" title="Permalink to this definition">¶</a></dt>
<dd><p>Generated lookup table (dict): returns the type of unit for a known input unit.
Note: Any unit must be <em>unique</em> because this dict is used to guess the
unit type.</p>
</dd></dl>

</div>
<div class="section" id="references">
<h2>7.8.4. References<a class="headerlink" href="#references" title="Permalink to this headline">¶</a></h2>
<table class="docutils citation" frame="void" id="jorgensen1998" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1">[Jorgensen1998]</a></td><td><ol class="first last upperalpha simple" start="23">
<li>Jorgensen, C. Jenson, J Comp Chem 19 (1998), 1179-1186</li>
</ol>
</td></tr>
</tbody>
</table>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="util.html" title="7.9. Helper functions — MDAnalysis.core.util"
             >next</a> |</li>
        <li class="right" >
          <a href="qcprot.html" title="7.7. Fast QCP RMSD structure alignment — MDAnalysis.core.qcprot"
             >previous</a> |</li>
        <li><a href="../../index.html">MDAnalysis v0.7.5-devel documentation</a> &raquo;</li>
          <li><a href="../core_modules.html" >7. Core modules</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2005-2011, Naveen Michaud-Agrawal, Elizabeth J. Denning, Joshua Adelman,
    Christian Beckstein (logo), David Caplan, Jan Domański, Philip Fowler,
    Joseph Goose, Benjamin Hall, Danny Parton, Tyler Reddy, Paul Rigor,
    and Oliver Beckstein.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>
  </body>
</html>